package cn.itcast.user.web;

import cn.itcast.user.config.PatternProperties;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;

    /* 路径： /user/110   */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) throws InterruptedException {
        if(id == 1){
            Thread.sleep(60);
        }else if(id == 2){
            throw new RuntimeException("故意抛出，触发熔断~~~");
        }
        return userService.queryById(id);
    }

//    @Value("${pattern.dateformat}")
//    private String dateformat;

    @Autowired
    private PatternProperties patternProperties;

/*
    @GetMapping("now")
    public String now(){
        return LocalDateTime.now().
                format(DateTimeFormatter.ofPattern(dateformat));
    }
*/

    @GetMapping("prop")
    public PatternProperties prop(){
        return patternProperties;
    }


}
